﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using LinQDemo.Models;

namespace LinQDemo.Models.SimpObject
{
    public class StudentRepository
    {
        private LinQDemoDataContext datacontent  = new LinQDemoDataContext();

        // 
        // Query Methods 

        public IQueryable<Student> FindAllStudents()
        {
            return datacontent.Students;
        }

        public Student GetStudent(string id)
        {
            return datacontent.Students.SingleOrDefault(s => s.StudentID == id);
        }

        // 
        // Insert/Delete Methods 

        public void Add(Student student)
        {
            datacontent.Students.InsertOnSubmit(student);
        }

        public void Delete(Student student)
        {

            /*
             Xoa het cac du lieu lien quan den table khac 
            datacontent.Classes.DeleteAllOnSubmit(dinner.RSVPs);
             */
            datacontent.Students.DeleteOnSubmit(student);
        }

        // 
        // Persistence  

        public void Save()
        {
            datacontent.SubmitChanges();
        } 
    }
}
